﻿using System;
using System.Management;
using System.Security.Cryptography;
using System.Text;

namespace TruckScale.Helpers
{
  public static class RegisterHelper
  {
    public static string GetHdInfo()
    {
      string StrHd = "";

      try
      {
        //获取硬盘物理序列号
        ManagementClass cimobject = new ManagementClass("Win32_DiskDrive");

        foreach (ManagementObject mo in cimobject.GetInstances())
        {
          if ("USB" != mo["InterfaceType"].ToString())
          {
            StrHd = mo["SerialNumber"].ToString().Trim();
          }
        }

        return StrHd;
      }
      catch (Exception)
      {
        return "";
      }
    }

    public static string Verify(string str)
    {
      string ret = "";
      string StrTemp = "";

      MD5 md5 = new MD5CryptoServiceProvider();
      byte[] data = Encoding.Default.GetBytes(str + "AWS3.1");
      byte[] result = md5.ComputeHash(data);
      for (int i = 0; i < result.Length; i++)
      {
        StrTemp += result[i].ToString("x").PadLeft(2, '0');
      }
      for (int j = 0; j < StrTemp.Length; j++)
      {
        ret += StrTemp[j];
        if (j > 6 && j < StrTemp.Length - 1 && (j + 1) % 8 == 0)
          ret += "-";
      }

      return ret.ToUpper();
    }
  }
}
